﻿// Shader-Based-Image-Processing (SBIP)
// http://code.google.com/p/sbip/
//
// Copyright © Frank Nagl, 2009-2010
// admin@franknagl.de
//
namespace SBIP.Filter
{
    using System;
    using Helper;

    /// <summary>
    /// Rotate RGB channels from image.
    /// </summary>
    /// 
    /// <remarks><para>The filter rotates RGB channels by specified channel order.</para>
    /// 
    /// <para>Sample usage:</para>
    /// <code>
    /// Bitmap image = new Bitmap( "cathedral.jpg" );
    ///
    /// // 1. Offline rendering of images
    /// // create Processor, used as rendering framework
    /// Processor processor = new Processor( );
    /// // starts Processor
    /// processor.Begin( image );
    /// // create RotateChannels filter
    /// RotateChannels filter = new RotateChannels( );
    /// processor.Filter = filter;
    /// // optional: configure filter
    /// filter.Order = RGBOrder.BGR;
    /// // apply the filter, render to bitmap  
    /// Bitmap resultImage = processor.RenderToBitmap( );
    /// resultImage.Save( "RotateChannels.jpg", ImageFormat.Jpeg );
    /// // apply the filter, render to texture
    /// // Texture2D resultTexture = processor.RenderToTexture( );
    /// processor.End( );
    ///  
    /// // 2. Online rendering of videos or images
    /// // create any windows control for rendering in
    /// Form myForm = new Form
    /// {
    ///     Width = 1280,
    ///     Height = 720
    /// };
    /// // starts Processor
    /// processor.Begin( "Video.avi", myForm );
    /// // create RotateChannels filter
    /// filter = new RotateChannels( );
    /// processor.Filter = filter;
    /// // optional: configure filter
    /// filter.Order = RGBOrder.GRB;
    /// // apply the filter
    /// myForm.Show( );
    /// while ( myForm.Created )
    /// {
    ///     processor.Render( );
    ///     Application.DoEvents( );
    /// }
    /// processor.End( );
    /// </code>
    /// 
    /// <para><b>Initial image:</b></para>
    /// <img src="../../Cathedral.jpg" width="500" height="338" />
    /// <para><b>Result image:</b></para>
    /// <img src="../../RotateChannels.jpg" width="500" height="338" />
    /// </remarks>
    public sealed class RotateChannels : BaseFilter
    {
        private RGBOrder order;
        
        /// <summary>The rotation order of RGB channels.</summary>
        /// <remarks><para>Default value is set to 
        /// <see cref="RGBOrder.GBR"/>.</para></remarks>
        public RGBOrder Order
        {
            get { return order; }
            set 
            {
                if (Effect == null)
                    throw new ArgumentException("RGB Order" + InitMsg);

                order = value;
                Effect.Parameters["Order"].SetValue((int)order);
            }
        }      
        
        /// <summary>
        /// Initializes a new instance of the <see cref="ReplaceChannel"/> class.
        /// </summary>
        public RotateChannels() : base("RotateChannels") { }

        /// <summary>
        /// Sets the <see cref="Order"/> value to 
        /// <see cref="RGBOrder.GBR"/>.
        /// </summary>
        protected override void PostInit()
        {
            Order = RGBOrder.GBR;
        }
    }
}
